/*
 * vfile.h
 *
 *  Created on: Dec 22, 2013
 *      Author: elazar
 */

#ifndef VFILE_H_
#define VFILE_H_
/******************************************************************************
 * This module defines the file container class.
 *
 *
 ******************************************************************************/
#include "dispatcher.h"
#include <vector>


/**************************************************************
 * This struct keeps the data of each version updated
 ***************************************************************/
struct Version {
	string maker;
	string comment;
	string time;
	Version(string maker, string comment):
		maker(maker), comment(comment) {}

	string info() const {
		string res = maker + ", " + time;
		if (!comment.empty())
			res += string("// ") + comment;
		return res;
	}
};

/**************************************************************************
 * Vfile class is the container of a file
 **************************************************************************/
class Vfile {
	string dir_name;
	std::vector<Version> versions;
	std::set<string> owners;
	string lock_user;

public:
	static string path;

	Vfile(string filename, string owner);

	void add_owner(string name);
	void remove_owner(string name);
	bool is_owner(string name);

	string get_last_version();
	string get_version_path(int version);
	string get_last_version_path();

	void checkout(string name);
	bool checked_out();
	bool checked_out_by(string name);
	void undo_checkout(string name);
	string add_version_to_path(Version v);

	void unlock_user();

	string get_description();
	string get_versions();
};




#endif /* VFILE_H_ */
